unit stokaral;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids, Wwdbigrd, Wwdbgrid, DBGrids, ImgList, db, wwSpeedButton,
  wwDBNavigator, ExtCtrls, wwclearpanel, Buttons, Wwkeycb, cxStyles,
  cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit,
  cxDBData, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGrid,
  cxDBLookupComboBox, Menus, cxImageComboBox, cxDropDownEdit, ADODB;

type
  TfStokaral = class(TForm)
    ImageList1: TImageList;
    Panel1: TPanel;
    bTamam: TBitBtn;
    bVazgec: TBitBtn;
    Timer1: TTimer;
    PopupMenu1: TPopupMenu;
    AmbarToplamlar1: TMenuItem;
    cxgrid1DBTableView1: TcxGridDBTableView;
    cxgrid1Level1: TcxGridLevel;
    cxgrid1: TcxGrid;
    cxgrid1DBTableView1stokkodu: TcxGridDBColumn;
    cxgrid1DBTableView1cinsi: TcxGridDBColumn;
    cxgrid1DBTableView1gstok: TcxGridDBColumn;
    MalzemeHarektleri1: TMenuItem;
    SipariHareketleri1: TMenuItem;
    Button1: TButton;
    bambartoplamlari: TButton;
    bmalzemehareketleri: TButton;
    bsiparishareketleri: TButton;
    cxgrid1DBTableView1bolum: TcxGridDBColumn;
    N1: TMenuItem;
    StokBul1: TMenuItem;
    adoUremri: TADOQuery;
    cxgrid1DBTableView1GrupKodu: TcxGridDBColumn;
    cxgrid1DBTableView1SayimGrubu: TcxGridDBColumn;
    cxgrid1DBTableView1Aktif: TcxGridDBColumn;
    cxgrid1DBTableView1UstGrupId: TcxGridDBColumn;
    cxgrid1DBTableView1GrupId: TcxGridDBColumn;
    cxgrid1DBTableView1MarkaId: TcxGridDBColumn;
    cxgrid1DBTableView1ModelId: TcxGridDBColumn;
    cxgrid1DBTableView1AltGrupId: TcxGridDBColumn;
    cxgrid1DBTableView1Anastokkodu: TcxGridDBColumn;
    MalzemeHarektleri2: TMenuItem;
    Button2: TButton;
    btEntegrasyon: TButton;
    cxgrid1DBTableView1uStok: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure bTamamClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure bVazgecClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure AmbarToplamlar1Click(Sender: TObject);
    procedure cxgrid1DBTableView1ColumnHeaderClick(
      Sender: TcxGridTableView; AColumn: TcxGridColumn);
    procedure cxgrid1DBTableView1CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure cxgrid1DBTableView1DblClick(Sender: TObject);
    procedure cxgrid1DBTableView1KeyPress(Sender: TObject;
      var Key: Char);
    procedure MalzemeHarektleri1Click(Sender: TObject);
    procedure SipariHareketleri1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure bambartoplamlariClick(Sender: TObject);
    procedure bmalzemehareketleriClick(Sender: TObject);
    procedure bsiparishareketleriClick(Sender: TObject);
    procedure StokBul1Click(Sender: TObject);
    procedure MalzemeHarektleri2Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure btEntegrasyonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fStokaral: TfStokaral;
  Siras: string;

implementation

uses data, ana1, Variants, AmbarToplamlari, MalzemeHareketleri,
  SiparisHareketleri, ExportForm, uremri, MalzemeHareketleri2;

{$R *.DFM}

procedure TfStokaral.FormShow(Sender: TObject);
begin
  Left := (Screen.Width - Width) div 2;
  Top := ((Screen.Height - Height) div 2) - 80;

  Siras := 'Stokkodu';
  if dm.stokara.Sort <> Siras then
    dm.stokara.Sort := Siras;

  anaform.CreateExport(Self);
  fStokaral.Timer1.enabled := true;

  btEntegrasyon.Visible := dm.servis.FieldByName('StokEntegrasyon').AsBoolean;
end;

procedure TfStokaral.bTamamClick(Sender: TObject);
begin
  modalresult := mrOk;
end;

procedure TfStokaral.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #27 then
  begin
    key := #0;
    bVazgecClick(sender);
  end
  else
    if key = #13 then
    begin
      key := #0;
      bTamamClick(sender);
    end;
end;

procedure TfStokaral.bVazgecClick(Sender: TObject);
begin
  modalresult := mrCancel;
end;

procedure TfStokaral.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  try
    if assigned(fStokaral) then
      cxgrid1.SetFocus;
  except
  end;
end;

procedure TfStokaral.AmbarToplamlar1Click(Sender: TObject);
begin
  if dm.StokAra.RecNo > 0 then
  begin
    AmbarToplamlariF := tAmbarToplamlariF.Create(Self);
    AmbarToplamlariF.StokKod := dm.StokAra.fieldbyname('stokkod').asinteger;
    AmbarToplamlariF.ShowModal;
  end;
end;

procedure TfStokaral.cxgrid1DBTableView1ColumnHeaderClick(
  Sender: TcxGridTableView; AColumn: TcxGridColumn);
begin
  if AColumn.SortOrder = soAscending then
  begin
    dm.stokara.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' DESC'
  end
  else
  begin
    dm.stokara.sort := copy(AColumn.Name, 20, length(AColumn.Name) - 19) + ' ASC';
  end;

  cxgrid1DBTableView1.OptionsBehavior.IncSearchItem := AColumn;
end;

procedure TfStokaral.cxgrid1DBTableView1CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  val: string;
begin
  ACanvas.Canvas.Font.Color := clblack;

  val := VarAsType(AViewInfo.GridRecord.DisplayTexts[cxgrid1DBTableView1gstok.Index], varString);

  if (val = '') or (val = '0') then
  begin
    val := VarAsType(AViewInfo.GridRecord.DisplayTexts[cxgrid1DBTableView1uStok.Index], varString);

    if (val = '') or (val = '0') then
      Exit;
  end;

  if StrToInt(val) > 0 then
  begin
    ACanvas.Canvas.Brush.Color := $00C1DCC0;
    ACanvas.Font.Style := [FsBold];
  end
  else
  begin
    ACanvas.Canvas.Brush.Color := clwhite;
  end;

  if AViewInfo.Selected then
  begin
    ACanvas.Canvas.Font.Color := clwhite;
    ACanvas.Canvas.Brush.Color := $00C56A31;
  end;
end;

procedure TfStokaral.cxgrid1DBTableView1DblClick(Sender: TObject);
begin
  bTamamClick(sender);
end;

procedure TfStokaral.cxgrid1DBTableView1KeyPress(Sender: TObject;
  var Key: Char);
begin
  if key = #13 then
    bTamamClick(sender);
end;

procedure TfStokaral.MalzemeHarektleri1Click(Sender: TObject);
begin
  if dm.stokara.RecNo > 0 then
  begin
    dm.islemid := dm.stokara.fieldbyname('stokkod').value;
    MalzemeHareketleriF := tMalzemeHareketleriF.create(Self);
    MalzemeHareketleriF.ShowModal;
  end;
end;

procedure TfStokaral.SipariHareketleri1Click(Sender: TObject);
begin
  if dm.stokara.RecNo > 0 then
  begin
    dm.islemid := dm.stokara.fieldbyname('stokkod').value;
    SiparisHareketleriF := tSiparisHareketleriF.create(Self);
    SiparisHareketleriF.ShowModal;
  end;

end;

procedure TfStokaral.Button1Click(Sender: TObject);
begin
  ExportAl(Self, 'Stok Listesi', dm.StokAra);
end;

procedure TfStokaral.bambartoplamlariClick(Sender: TObject);
begin
  AmbarToplamlar1Click(Sender);
end;

procedure TfStokaral.bmalzemehareketleriClick(Sender: TObject);
begin
  MalzemeHarektleri1Click(Sender);
end;

procedure TfStokaral.bsiparishareketleriClick(Sender: TObject);
begin
  SipariHareketleri1Click(Sender);
end;

procedure TfStokaral.StokBul1Click(Sender: TObject);
var
  InputString: string;
begin
  InputString := InputBox('Stok Kodu', 'Giriniz :', '');
  dm.stokara.Locate('stokkodu', InputString, [loPartialKey]);
end;

procedure TfStokaral.MalzemeHarektleri2Click(Sender: TObject);
begin
  if dm.stokara.RecNo > 0 then
  begin
    dm.islemid := dm.stokara.fieldbyname('stokkod').value;
    MalzemeHareketleriF2 := TMalzemeHareketleriF2.create(Self, Self, FsNormal);
    MalzemeHareketleriF2.ShowModal;
  end;
end;

procedure TfStokaral.Button2Click(Sender: TObject);
begin
  MalzemeHarektleri2Click(Sender);
end;

procedure TfStokaral.btEntegrasyonClick(Sender: TObject);
begin
  if dm.servis.FieldByName('StokEntegrasyon').AsBoolean then
  begin
    with dm.Bosislem do
    begin
      Close;
      SQL.Text := 'EXEC sp_Entegrasyon 1,100';
      ExecSQL;
    end;
  end;

end;

end.

